<?php


/**
 * Add language to a user, which he can translate to.
 *
 *
 * @package BABEL
 * @since   BABEL 0.1.0
 * @version $Id: add_language.php 769 2008-05-14 11:07:55Z hauknu $
 * @copyright Copyright (C) 2008 Knut Haug 
 * @author  Knut Haug
 * @license LGPL
 */

include('includes/babel/prepend_no_gui.php');

$lang=$_GET["action"];

/*
 * SQL statement which adds a new language to a user, that enables him to 
 * translate constants to that language.
 *
 * 2params:
 * $_SESSION["user"]["user_id"] 	- The current user who is logged in
 * $lang 							- The language id of the new language he
 */
$DB_QUERY = 
			"INSERT INTO 
				babel_user_skills(
								  status,
								  skill, 
								  user_id, 
								  language_id) 
			VALUES(1, ?, ?, ?)";

/* Executes the query, and throws an exeption if it failed. 
 * 
 * 1param:
 * String - Message that should be printed as error message
 */
if (!PDODB::execQuery($DB_QUERY, array(BABEL_STARTING_USER_SKILL, $_SESSION["user"]["user_id"], $lang))) {
	throw new Exception("Add language to user: query failed");
}
// Sets the current language to 0
$_SESSION["user"]["profile"]["language"][$lang] = 10;


